package com.felight;

public class calculator {
	 
	 

	
	 	
	 public static int[] randomInt(int d) 
	   {
	 	int[] a = new int[d];
	 	for(int i = 0; i<d; i++)
	 	a[i]=(int) (Math.random()*100);
	 	return a;
	 }
	 	
	 	
	 public static double[] randomDouble(int num) 
	   {
	 	double[] a = new double[num];
	 	for(int i = 0; i<num; i++)
	 	a[i]=Math.random()*100;
	 	return a;
	 }
	 	
	 public static char[] randomChar(int num) 
	   {
	 	char temp;
	 	char[] a = new char[num];
	 	int i=0;
	 	while(i<num) 
	 	{
	 	 temp = (char) (Math.random()*100);
	 	 if((temp >='a' && temp <= 'z' )||(temp >= 'A' && temp <= 'Z'))
	 	a[i++]=temp;	
	 	}
	 	return a;
	 }
	 	
	 public static void printInt(int[] array)
	  {
	 		for(int i=0;i<array.length;i++)
	 		System.out.print(array[i] + ",");
	 }
	 	
	 public static void printDouble(double[] array)
	  {
	 		for(int i=0;i<array.length;i++)
	 		System.out.print(array[i] + ",");
	 }
	 	
	 public static void printChar(char[] array)
	  {
	 		for(int i=0;i<array.length;i++)
	 		System.out.print(array[i] + ",");
	 }
	 	
	 public static int maxArray(int[] array)
	  {
	 	
	 	int max=0;
	 	for(int i=0;i<array.length;i++)
	 		if(max<array[i])
	 		max = array[i];
	 	return max;
	 }
	 public int[] revInt(int[] array)
	  {
	 	
	 	int[] rev = new int[array.length];
	 	for(int i=0;i<array.length;i++)
	 	rev[array.length-i-1] = array[i];
	 	return rev;
	 	
	 }
	 public static char[] revChar(char[] array)
	  {
	 	char[] rev = new char[array.length];
	 	for(int i=0;i<array.length;i++)
	 	rev[array.length-i-1] = array[i];
	 	return rev;
	 }
	 	
	 public static int countVowel(char[] array)
	  {
	 	int count=0;
	 	for(int i=0;i<array.length;i++)
	 	if(array[i]=='a'||array[i]=='e'||array[i]=='i'||array[i]=='o'||array[i]=='u'||
	 	array[i]=='A'||array[i]=='E'||array[i]=='I'||array[i]=='O'||array[i]=='U')
	 	count++;
	 	return count;
	 }
	 	
	 public static int[] generateEven(int num1,int num2)
	  {
	 	int[] array = new int[50];
	 	for(int i=num1,j=0;i<=num2;i++,j++)
	 	if(i%2==0)
	 	array[j]=i;
	 	else
	 	j--;
	 	return array;
	 }
	 	
	 	
	 public static int[] generateOdd(int num1,int num2)
	  {
	 	int[] array= new int[50];
	 	for(int i=num1,j=0;i<=num2;i++,j++)
	 	if(!(i%2==0))
	 	array[j]=i;
	 	else
	 	j--;
	 	return array;
	 }
	 	
	 public static int[] generatePrime(int num1,int num2)
	  {
	 	int[] array = new int[50];
	 	for(int i=num1,j=0;i<=num2;i++,j++)
	 	if(isPrime(i))
	 	array[j]=i;
	 	else
	 	j--;
	 	return array;
	 }

	 public static boolean isPrime(long num)
	  {
	 	boolean result = false;
	 	long count = 0;
	 	long i=2;
	 	while(i <= num/2) {
	 	if(num%i == 0)
	 	count++;
	 	i++;
	 }
	 	if(count == 0 && num != 1 && num != 0)
	 	result = true;
	 	return result;
	 }	
	 	
	 	
	 public int[] generateFibonacci(int num)
	  {

	 	   int[] fib=new int[num];
	  	   fib[0] = 0;
	 	   fib[1] = 1; 
	 	   for(int i=2;i<fib.length;i++)
	 	 {
	 	   fib[i]=fib[i-1]+fib[i-2];
	 	 }
	 	return (fib);   
	 }


	 	public static int[][] generateRandomMatrix(int row , int col)
	 	{		
	 		int[][] matrix = new int[row][col];
	 		int a;
	 		for(int i=0;i<matrix.length;i++) {
	 			for(int j=0;j<matrix[i].length;j++)
	 				{
	 					a = (int)(Math.random()*100);
	 					if(a>0&&a<10)
	 						matrix[i][j] = a;
	 					else
	 						j--;
	 				}
	 		}
	 		return matrix;
	 	}
	 	
	 	
	 	public static void printMatrix(int[][] matrix)
	 	{		
	 		for(int i=0;i<matrix.length;i++) {
	 			for(int j=0;j<matrix[i].length;j++)
	 					System.out.print(matrix[i][j]+" ");
	 			System.out.println();
	 		}
	 	}
	 	
	 	public static int[][] addMatrix(int[][] matA , int[][] matB)
	 	{
	 		int[][] result = new int[matA.length][matA[0].length];
	 		for(int i=0;i<matA.length;i++) 
	 			for(int j=0;j<matB[i].length;j++)
	 					result[i][j] = matA[i][j] + matB[i][j];
	 		return result;
	 	}
	 	
	 	public static int[][] multiMatrix(int[][] matA , int[][] matB)
	 	{		
	 		int[][] result = new int[matA.length][matB[0].length];
	 		int sum=0;
	 		for(int i=0;i< matA.length;i++) 
	 			for(int j=0;j<matB[0].length;j++) 
	 				for(int k=0 ; k < matB.length ;k++) 
	 					result[i][j] = result[i][j] + (matA[i][k] * matB[k][j]);
	 		return result;
	 	}
	 	
	 	
	 	public static long sumMatrix(int[][] matrix) 
	 	{		
	 		long sum = 0;
	 		for(int i=0;i<matrix.length;i++) 
	 			for(int j=0;j<matrix[i].length;j++)
	 					sum = sum + matrix[i][j];
	 			
	 		return sum;
	 	}
	 	
	 	public static int[] sumRow(int[][] matrix)
	 	{		
	 		int sum[] = new int[matrix.length];
	 		for(int i=0;i<matrix.length;i++) 
	 			for(int j=0;j<matrix[i].length;j++)
	 					sum[i] = sum[i] + matrix[i][j];			
	 		return sum;
	 	}
	 	
	 	public static int[] sumCol(int[][] matrix)
	 	{		
	 		int sum[] = new int[matrix[0].length];
	 		for(int i=0;i<matrix.length;i++) 
	 			for(int j=0;j<matrix[i].length;j++)
	 					sum[j] = sum[j] + matrix[i][j];			
	 		return sum;
	 	}
	 	
	 	public static void bubbleSort(int[] matrix)
	 	{	
	 		for(int i = 0; i < matrix.length; i++) 
	 			for(int j = i+1 ; j < matrix.length;j++)
	 					if(matrix[i]>matrix[j])
	 					{
	 						int temp = matrix[i];
	 						matrix[i] = matrix[j];
	 						matrix[j] = temp;
	 					}
	 	}
	 	
	 	public static void selectionSort(int[] matrix)
	 	{
	 		int pos = -1;		
	 		for(int i = 0; i < matrix.length; i++)
	 		{
	 			pos = i;
	 			for(int j = i+1 ;j < matrix.length; j++)
	 				if(matrix[j]<matrix[pos])
	 					pos = j;				
	 			int temp = matrix[pos];
	 				matrix[pos] = matrix[i];
	 				matrix[i] = temp;
	 		}
	 	}

	 	public static int[] generateRandomMatrix(int size)
	 	{
	 		int[] matrix = new int[size];
	 		int a;
	 		for(int i=0;i<matrix.length;i++)
	 		{
	 		   a = (int)(Math.random()*100);
	 		          if(a>0&&a<10)
	 			matrix[i] = a;
	 			else
	 			i--;
	 				
	 		}
	 		return matrix;
	 	}
	 	
	 	public static void printMatrix(int[] mat)
	 	{
	 		for(int i = 0 ; i < mat.length ; i++ )
	 		{
	 			System.out.print(mat[i]+",");
	 		}
	 	}

		public int arrsum(int[] result, int[] a) {
				
			 	int sum = 0 ;
			 	for(int i=0;i<a.length;i++)
			 	sum = sum + a[i]; 
			 	return sum;
		}

		public int ADD(int i, int j) {
			 
			int ADD = i + j;
			return ADD;
		}
	 	
	 }


